<template>
	<view class="pages">
		<!-- 	<view class="">
			<u-tabs :list="typelist" :show-bar="false" :is-scroll="false" :current="current"
				@change="change"></u-tabs>
		</view> -->
		<view class="voucher-list box-content">
			<view :class="priceRatio(item.use_price)?'item-voucher' :'item-voucher gray' " v-for="(item,index) in list" :key="index">
				<view class="left-info">
					<view class="title">足浴按摩 <text class="price">{{item.reduction_price}}元</text><text>代金券</text></view>
					<view class="man-txt">满{{item.use_price}}使用</view>
				</view>
				<view class="right-info">
					<view class="price"><text>￥</text>{{item.reduction_price}} </view>
					<view class="choose-btn use" v-if="!item.isChoose && priceRatio(item.use_price)"
						@click="chooseVoucher(item,index)">使用</view>
					<view class="choose-btn use" v-else-if="item.isChoose  && priceRatio(item.use_price)"
						@click="chooseVoucher(item,index)">取消</view>
						<view class="choose-btn use" v-else-if="!priceRatio(item.use_price)">不可使用</view>
				</view>
				<image class="fixed-use" src="https://qiniu-cdn.maeiyun.com/imgs/mine/b2.png" mode=""></image>
			</view>
		</view>
	</view>
</template>

<script>
	import publicData from './public.js'
	import Bignumber from '../../common/js/bignumber.js'
	export default {
		data() {
			return {
				list: [],
				type: 0, //选择  1展示,
				page: 1,
				page1: 1,
				typelist: [{
					name: '全部',
					id: 0
				}, {
					name: '待领取',
					id: 1
				}, {
					name: '已领取',
					id: 2
				}],
				current: 0,
				id: "",
				money: 0
			}
		},
		onLoad(option) {
			this.id = option.id
			this.money = option.money
			this.getGainVoucherList()
		},
		onReachBottom() {
			this.getGainVoucherList()
		},
		methods: {
			priceRatio(price) {
				var aa = new Bignumber(this.money).comparedTo(new Bignumber(price))
				if (aa == 0 || aa == 1) {
					return true
				} else {
					return false
				}
			},
			getGainVoucherList() {
				let that = this
				this.request.httpTokenRequest({
					url: "ticket/myTicket",
					method: "get"
				}, {
					page: this.page1
				}).then(res => {
					if (res.code == 0) {
						that.page1++
						res.data.data.map(item => {
							if (that.id == item.user_ticket_id) {
								item.isChoose = true
							} else {
								item.isChoose = false
							}
							that.list.push(item)
						})
					} else {
						this.$util.msg(res.msg)
						return
					}
				}, error => {})
			},
			chooseVoucher(item, index) {
				this.list[index].isChoose = !this.list[index].isChoose
				let pages = getCurrentPages();
				let prevPage = pages[pages.length - 2];
				if (this.list[index].isChoose) {
					// #ifdef APP
					prevPage.$vm.voucher = item
					// #endif
					// #ifndef APP
					prevPage.voucher = item
					// #endif
				} else {
					// #ifdef APP
					prevPage.$vm.voucher = {}
					// #endif
					// #ifndef APP
					prevPage.voucher = {}
					// #endif
				}
				uni.navigateBack({})
			},

		}
	}
</script>

<style lang="scss">
	.pages {
		// padding-top:var(--status-bar-height) ;
	}
	.gray {
	    filter: grayscale(100%); /* 设置为完全灰度 */
	}
	.voucher-list {
		padding: 0 30rpx;
	}

	.item-voucher {
		background: url('https://qiniu-cdn.maeiyun.com/imgs/mine/b1.png')no-repeat;
		background-size: 100% 100%;
		height: 160rpx;
		display: flex;
		align-items: center;
		margin-top: 20rpx;
		position: relative;

		.fixed-use {
			width: 121rpx;
			height: 90rpx;
			position: absolute;
			bottom: 35rpx;
			right: 210rpx;
		}

		.left-info {
			padding-left: 42rpx;

			.title {
				font-size: 30rpx;
				font-weight: 400;
				color: #525252;
				line-height: 42rpx;
				display: flex;
				align-items: center;

				.price {
					color: #D84A4C;
					font-size: 30rpx;
					margin-left: 30rpx;
				}
			}

			.man-txt {
				font-size: $uni-font-size-sm;
				font-weight: 400;
				color: #A8A8A8;
				line-height: 28rpx;
				margin-top: 10rpx;
			}

			.time {
				font-size: 20rpx;
				font-family: MaoKenTangYuan, MaoKenTangYuan;
				font-weight: normal;
				color: #FFFFFF;
			}
		}

		.right-info {
			margin-left: auto;
			margin-right: 23rpx;
			text-align: center;

			.price {
				font-size: 40rpx;
				font-weight: 400;
				color: #FFFFFF;
				line-height: 56rpx;

				text {
					font-size: 28rpx;
					font-weight: 400;
					color: #FFFFFF;
				}
			}

			.choose-btn {
				width: 116rpx;
				height: 40rpx;
				background: rgba(255, 255, 255, 0.64);
				border-radius: 25rpx;
				border: 3rpx solid rgba(255, 255, 255, 0.33);
				font-size: $uni-font-size-sm;
				font-weight: 400;
				color: #9E2527;
				text-align: center;
				line-height: 40rpx;
			}

			.use {
				background: rgba(255, 255, 255, 0.9)
			}
		}
	}
</style>